import fetch from 'dva/fetch';

let _host

function checkStatus(response) {
  if (response.status >= 200 && response.status < 300) {
    return response;
  }

  const error = new Error(response.statusText);
  error.response = response;
  throw error;
}
_host='https://api.salesgj.com';

export default async function request(url, options) {
  // return fetch(url, options)
  //   .then(checkStatus)
  //   .then(parseJSON)
  //   .then(data => ({ data }))
  //   .catch(err => ({ err }));
  options.headers = {
    Authorization : window.localStorage['token'],
    // Accept: 'application/json, text/plain, */*',
    // "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
    "Content-Type": "application/json"
  }
  const response = await fetch(_host+ url, options);

  checkStatus(response);

  const data = await response.json();

  const ret = {
    data,
    headers: {},
  };

  // if (response.headers.get('x-total-count')) {
  //   ret.headers['x-total-count'] = response.headers.get('x-total-count');
  // }

  return ret;
}
